import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

	private static InputReader inputReader = new InputReader();

	private static BoxSorter boxSorter = new BoxSorter();

	public static void main(String[] args) {

		String line = null;
		boolean baseLine = true;
		int boxNumber = 0;
		InputMatrix inputMatrix = null;
		while ((line = readLine()) != null) {
			if ("".equals(line.trim())) {
				break;
			}
			if (baseLine == true) {
				inputMatrix = inputReader.createInputMatrix(line);
				baseLine = false;
			} else {
				inputReader.updateInputMatrix(inputMatrix, boxNumber++, line);
			}

			if (boxNumber == inputMatrix.getNumberOfBoxes()) {
				printResult(inputMatrix);
				baseLine = true;
				boxNumber = 0;
			}
		}
	}

	private static String readLine() {
		final int maxLength = 255;
		byte line[] = new byte[maxLength];
		int lg = 0, character = -1;

		try {
			while (lg < maxLength) {
				character = System.in.read();
				if ((character < 0) || (character == '\n')) {
					break;
				}
				line[lg++] += character;
			}
		} catch (IOException e) {
			return (null);
		}

		if ((character < 0) && (lg == 0)) {
			return (null);
		}
		return (new String(line, 0, lg));
	}

	private static void printResult(InputMatrix inputMatrix) {
		List<Integer> result = boxSorter.sortBoxes(inputMatrix);
		System.out.println(result.size());
		String sequence = "";
		for (Integer each : result) {
			sequence += each + " ";
		}
		System.out.println(sequence);
	}

}

class BoxSorter {

	public List<Integer> sortBoxes(InputMatrix inputMatrix) {
		sortDimensions(inputMatrix);
		EngineContext context = new EngineContext(inputMatrix.getNumberOfBoxes());
		stackBoxes(context, inputMatrix);
		List<Integer> result = findLongestSequence(context);
		return incrementToBoxNumbers(result);
	}

	private void sortDimensions(InputMatrix inputMatrix) {
		for (Integer[] each : inputMatrix.getBoxesWithSizes()) {
			Arrays.sort(each);
		}
	}

	private void stackBoxes(EngineContext context, InputMatrix inputMatrix) {
		Integer[][] boxes = inputMatrix.getBoxesWithSizes();
		for (int i=0; i<boxes.length; i++) {
			for (int j=0; j<boxes.length; j++) {
				if (i==j) {
					continue;
				}
				if (boxOneFitsBoxTwo(boxes[i], boxes[j])) {
					context.addBoxToStack(i, j);
				}
			}
		}
	}

	private boolean boxOneFitsBoxTwo(Integer[] boxOne, Integer[] boxTwo) {
		int boxDimension = boxOne.length;
		for (int i=0; i<boxDimension; i++) {
			if (boxOne[i] >= boxTwo[i]) {
				return false;
			}
		}
		return true;
	}

	private List<Integer> findLongestSequence(EngineContext context) {
		List<Integer> longest = null;
		for (int i=0; i<context.getStackingBoxes().length; i++) {
			List<Integer> list = getStackingStringForBox(i, context.getStackingBoxes());
			if (longest == null || list.size() > longest.size()) {
				longest = list;
			}
		}
		return longest;
	}

	private List<Integer> getStackingStringForBox(int boxNumber, List<Integer>[] stackingBoxes) {
		List<Integer> sequence = new ArrayList<Integer>();
		sequence.add(boxNumber);
		if (stackingBoxes[boxNumber] == null) {
			return sequence;
		}

		List<Integer> longest = null;
		for (Integer each : stackingBoxes[boxNumber]) {
			List<Integer> boxesString = getStackingStringForBox(each, stackingBoxes);
			if (longest == null || boxesString.size() > longest.size()) {
				longest = boxesString;
			}
		}
		sequence.addAll(longest);
		return sequence;
	}

	private List<Integer> incrementToBoxNumbers(List<Integer> sequence) {
		for (int i=0; i<sequence.size(); i++) {
			sequence.set(i, sequence.get(i) + 1);
		}
		return sequence;
	}

	class EngineContext {

		private List<Integer>[] stackingBoxes;

		@SuppressWarnings("unchecked")
		public EngineContext(int numerOfBoxes) {
			this.stackingBoxes = new ArrayList[numerOfBoxes];
		}

		public void addBoxToStack(Integer boxIndex, Integer biggerBoxIndex) {
			if (this.stackingBoxes[boxIndex] == null) {
				this.stackingBoxes[boxIndex] = new ArrayList<Integer>();
			}
			this.stackingBoxes[boxIndex].add(biggerBoxIndex);
		}

		public List<Integer>[] getStackingBoxes() {
			return this.stackingBoxes;
		}

	}

}

class InputReader {

	public InputMatrix createInputMatrix(String firstLine) {
		Integer[] baseNumbers = getIntegersFromLine(firstLine);
		return new InputMatrix(baseNumbers[0], baseNumbers[1]);
	}

	public void updateInputMatrix(InputMatrix inputMatrix, int boxNumber, String line) {
		Integer[] sizes = getIntegersFromLine(line);
		inputMatrix.addNewBox(boxNumber, sizes);
	}

	private Integer[] getIntegersFromLine(String line) {
		List<Integer> numbers = new ArrayList<Integer>();
		for (String each : line.trim().split("\\s+")) {
			numbers.add(new Integer(each));
		}
		return numbers.toArray(new Integer[] {});
	}

}

class InputMatrix {

	private int numberOfBoxes;

	private int numberOfDimensions;

	private Integer[][] boxesWithSizes;

	public InputMatrix(Integer numberOfBoxes, Integer numberOfDimensions) {
		this.numberOfBoxes = numberOfBoxes;
		this.numberOfDimensions = numberOfDimensions;
		this.boxesWithSizes = new Integer[numberOfBoxes][];
	}

	public int getNumberOfBoxes() {
		return numberOfBoxes;
	}

	public void setNumberOfBoxes(int numberOfBoxes) {
		this.numberOfBoxes = numberOfBoxes;
	}

	public int getNumberOfDimensions() {
		return numberOfDimensions;
	}

	public void setNumberOfDimensions(int numberOfDimensions) {
		this.numberOfDimensions = numberOfDimensions;
	}

	public void addNewBox(int boxNumber, Integer[] sizes) {
		this.boxesWithSizes[boxNumber] = sizes;
	}

	public Integer[] getBoxSizes(int boxNumber) {
		return this.boxesWithSizes[boxNumber];
	}

	public Integer[][] getBoxesWithSizes() {
		return this.boxesWithSizes;
	}

}

